// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: Logo Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

// Aliases
private alias object.value0  : logo.timer
private alias object.value1  : logo.playerX
private alias object.value2  : logo.playerY
private alias object.value3  : logo.paletteTimer
private alias object.value4  : logo.arrayPos
private alias object.value5  : logo.armFrame
private alias object.value6  : logo.armX
private alias object.value7  : logo.armY
private alias object.value8  : logo.charTitlePos
private alias object.value9  : logo.speedPercent
private alias object.value10 : logo.disablePaletteRotation //not actually used as far as I can tell
private alias object.value11 : logo.player2X
private alias object.value12 : logo.player2Y
private alias object.value13 : logo.p2Frame
private alias object.value14 : logo.levelSelectCheatPos
private alias object.value15 : logo.debugModeCheatPos
private alias object.value16 : logo.regionSwitchCheatPos

//STATES
//The first 3 states are identical so there's really not much reason to have em seperate but it is what it is

private alias 0  : LOGO_SETUP_SONIC
private alias 1  : LOGO_FADEIN_SONIC
private alias 2  : LOGO_RISEDELAY_SONIC
private alias 3  : LOGO_RISE_SONIC
private alias 4  : LOGO_ANIMATE_SONIC
private alias 5  : LOGO_FINGERWIGGLE_SONIC
private alias 6  : LOGO_P2TEXTAPPEAR_SONIC
private alias 7  : LOGO_MOVELEFT_SONIC
private alias 8  : LOGO_RISEP2_SONIC
private alias 9  : LOGO_ANIMATEP2_SONIC
private alias 10 : LOGO_ARMAPPEARP2_SONIC
private alias 11 : LOGO_ANIMATEP1_SONIC

private alias 0  : LOGO_SETUP_TAILS
private alias 1  : LOGO_FADEIN_TAILS
private alias 2  : LOGO_RISEDELAY_TAILS
private alias 3  : LOGO_RISE_TAILS
private alias 4  : LOGO_ANIMATE_TAILS
private alias 5  : LOGO_ARMAPPEAR_TAILS
private alias 6  : LOGO_PREPLOGOAPPEAR_TAILS
private alias 7  : LOGO_SHOWLOGO_TAILS
private alias 8  : LOGO_IDLE_TAILS

private alias 0  : LOGO_SETUP_KNUX
private alias 1  : LOGO_FADEIN_KNUX
private alias 2  : LOGO_RISEDELAY_KNUX
private alias 3  : LOGO_RISE_KNUX
private alias 4  : LOGO_ANIMATE_KNUX
private alias 5  : LOGO_ARMAPPEAR_KNUX
private alias 6  : LOGO_ANIMATEARM_KNUX
private alias 7  : LOGO_MOVEARM_KNUX
private alias 8  : LOGO_PREPLOGOAPPEAR_KNUX
private alias 9  : LOGO_ARMAPPEAR2_KNUX
private alias 10 : LOGO_ANIMATEARM2_KNUX
private alias 11 : LOGO_MOVEARM2_KNUX
private alias 12 : LOGO_SHOWLOGO_KNUX
private alias 13 : LOGO_IDLE_KNUX

// Function declarations
reserve function Logo_CheckControllerCheatCodes

// Tables
public table Logo_PlayerColors
	0x6060A0, 0x80A0E0, 0xE08000, 0xE0C080, 0xA04000, 0x600000, 0xE02080, 0xE00040, 0x800000, 0x806080, 0xA08060, 0xE0C0A0, 0x80A0A0, 0xA04020
end table

public table Logo_TailsBodyOffsets
	-50, -40, -53, -56, -58, -68, -60, -74, -62, -78, -63, -79, -64, -80
end table

public table Logo_TailsArmOffsets
	5, -32, 6, -31
end table


function Logo_CheckControllerCheatCodes
	temp0 = 0 // keyID
	if inputPress.up == true
		temp0 = 1
	end if
	if inputPress.down == true
		temp0 = 2
	end if
	if inputPress.left == true
		temp0 = 3
	end if
	if inputPress.right == true
		temp0 = 4
	end if
	if inputPress.buttonA == true
		temp0 = 5
	end if
	if inputPress.buttonB == true
		temp0 = 6
	end if
	if inputPress.buttonC == true
		temp0 = 7
	end if

	// 1, 2, 3, 4 = up, down, left, right
	switch logo.levelSelectCheatPos
	case 0
		if temp0 == 1
			logo.levelSelectCheatPos++
		else
			if temp0 != 0
				logo.levelSelectCheatPos = 0
			end if
		end if
		break
	case 1
		if temp0 == 2
			logo.levelSelectCheatPos++
		else
			if temp0 != 0
				logo.levelSelectCheatPos = 0
			end if
		end if
		break
	case 2
		if temp0 == 3
			logo.levelSelectCheatPos++
		else
			if temp0 != 0
				logo.levelSelectCheatPos = 0
			end if
		end if
		break
	case 3
		if temp0 == 4
			logo.levelSelectCheatPos++
			logo.levelSelectCheatPos = 0
			options.stageSelectFlag = 1
			PlaySfx(SfxName[Ring L], false)
		else
			if temp0 != 0
				logo.levelSelectCheatPos = 0
			end if
		end if
		break
	end switch

	//1, 7, 2, 7, 3, 7, 4, 7 = up, C, down, C, left, C, right, C
	switch logo.debugModeCheatPos
	case 0
		if temp0 == 1
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 1
		if temp0 == 7
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 2
		if temp0 == 2
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 3
		if temp0 == 7
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 4
		if temp0 == 3
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 5
		if temp0 == 7
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 6
		if temp0 == 4
			logo.debugModeCheatPos++
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	case 7
		if temp0 == 7
			logo.debugModeCheatPos = 0
			stage.debugMode = 1
			PlaySfx(SfxName[Ring L], false)
		else
			if temp0 != 0
				logo.debugModeCheatPos = 0
			end if
		end if
		break
	end switch

	//1, 2, 1 = up, down, up
	switch logo.regionSwitchCheatPos
	case 0
		if temp0 == 1
			logo.regionSwitchCheatPos++
		else
			if temp0 != 0
				logo.regionSwitchCheatPos = 0
			end if
		end if
		break
	case 1
	case 2
	case 3
	case 4
		if temp0 == 2
			logo.regionSwitchCheatPos++
		else
			if temp0 != 0
				logo.regionSwitchCheatPos = 0
			end if
		end if
		break
	case 5
		if temp0 == 1
			logo.regionSwitchCheatPos++
			logo.regionSwitchCheatPos = 0
			options.region ^= 1
			PlaySfx(SfxName[Ring L], false)
		else
			if temp0 != 0
				logo.regionSwitchCheatPos = 0
			end if
		end if
		break
	end switch
end function


event ObjectMain
	if stage.player2Enabled == true
		stage.playerListPos = 3
	end if

	if logo.disablePaletteRotation == false
		logo.paletteTimer++
		if logo.paletteTimer == 6
			logo.paletteTimer = 0
			RotatePalette(0, 192, 195, 1)
		end if
	end if

	// if no save
	if options.gameMode == 0
		if object.state > LOGO_RISE_SONIC
			CallFunction(Logo_CheckControllerCheatCodes)
		end if
	end if
end event


event ObjectDraw
	temp0 = true
	switch stage.playerListPos
	case 1
		if object.state == LOGO_P2TEXTAPPEAR_SONIC
			temp0 = false
		end if
		break

	case 2
		if object.state == LOGO_IDLE_TAILS
			temp0 = false
		end if
		break

	case 3
		if object.state == LOGO_ANIMATEARM_KNUX
			temp0 = false
		end if
		break

	end switch

	//Draw Logo (Top Half)
	if temp0 != false
		DrawSpriteScreenXY(9, screen.xcenter, object.ypos)
	end if

	switch stage.playerListPos
	case 0
	case 3
		switch object.state
		case LOGO_SETUP_SONIC
			screen.xoffset 		 = 0

			object.priority 	 = PRIORITY_ACTIVE
			logo.timer 			 = 1000
			stage.activeLayer[0] = 1 //set bg to lowest layer
			object.state++

			SetScreenFade(0x00, 0x00, 0x00, 0xFF)
			break

		case LOGO_FADEIN_SONIC
			screen.xoffset += 2

			if logo.timer > 0
				logo.timer -= 8
			else
				PlayMusic(0)
				object.state++
			end if

			SetScreenFade(0x00, 0x00, 0x00, logo.timer)
			break

		case LOGO_RISEDELAY_SONIC
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 38
				logo.timer = 0
				logo.playerY = 186
				object.frame = 0
				object.state++
			end if
			break

		case LOGO_RISE_SONIC
			screen.xoffset += 2

			logo.playerY -= 8
			if logo.playerY < 144
				object.frame = 1
			end if
			if logo.playerY <= 112
				logo.playerY = 112
				object.state++
			end if

			DrawSpriteScreenXY(object.frame, screen.xcenter, logo.playerY)
			break

		case LOGO_ANIMATE_SONIC
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 8
				object.frame++
				if object.frame >= 7
					object.frame = 7
					object[+1].type 	= TypeName[Start Message]
					object[+1].priority = PRIORITY_ACTIVE
					object[+1].xpos 	= screen.xcenter
					if stage.playerListPos == 3
						object[+1].ypos = 216
						object.state 	= LOGO_P2TEXTAPPEAR_SONIC
					else
						object[+1].ypos = 192
						object.state++
					end if
				end if
				logo.timer = 0
			end if

			DrawSpriteScreenXY(object.frame, screen.xcenter, logo.playerY)
			break

		case LOGO_FINGERWIGGLE_SONIC
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 8
				object.frame++
				if object.frame > 8
					object.frame = 7
				end if
				logo.timer = 0
			end if

			DrawSpriteScreenXY(9, screen.xcenter, object.ypos)
			DrawSpriteScreenXY(object.frame, screen.xcenter, logo.playerY)
			break

		case LOGO_P2TEXTAPPEAR_SONIC
			screen.xoffset += 2

			object.ypos -= 2
			logo.playerY -= 2
			if object.ypos <= -24
				logo.charTitlePos = screen.xsize
				logo.charTitlePos += 108
				object.state++
				logo.playerX = screen.xcenter
			end if

			DrawSpriteScreenXY(9, screen.xcenter, object.ypos)
			DrawSpriteScreenXY(object.frame, screen.xcenter, logo.playerY)
			break

		case LOGO_MOVELEFT_SONIC
			screen.xoffset += 2

			logo.timer++
			logo.playerX++
			logo.charTitlePos -= 8
			temp0 = screen.xcenter
			temp0 += 12
			if logo.charTitlePos <= temp0
				logo.charTitlePos = temp0
				logo.p2Frame = 12
				object.state++
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if options.region == 1
				DrawSpriteScreenXY(33, logo.charTitlePos, 228)
			else
				DrawSpriteScreenXY(31, logo.charTitlePos, 228)
			end if
			DrawSpriteScreenXY(36, logo.charTitlePos, 228)
			break

		case LOGO_RISEP2_SONIC
			screen.xoffset += 2

			temp0 = logo.arrayPos
			GetTableValue(logo.player2X, temp0, Logo_TailsBodyOffsets)
			logo.player2X += screen.xcenter
			logo.player2X -= 24
			temp0++

			GetTableValue(logo.player2Y, temp0, Logo_TailsBodyOffsets)
			logo.player2Y += screen.ycenter
			logo.player2Y -= 24

			logo.timer++
			logo.timer &= 3
			if logo.timer == 0
				logo.arrayPos += 2
				if logo.arrayPos == 14
					object.state++
				end if
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.p2Frame, logo.player2X, logo.player2Y)
			if options.region == 1
				DrawSpriteScreenXY(33, logo.charTitlePos, 258)
			else
				DrawSpriteScreenXY(31, logo.charTitlePos, 258)
			end if
			DrawSpriteScreenXY(36, logo.charTitlePos, 258)
			break

		case LOGO_ANIMATEP2_SONIC
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 2
				logo.p2Frame++
				if logo.p2Frame >= 16
					logo.p2Frame = 16
					logo.armX = 8
					logo.armX += screen.xcenter
					logo.armY = -27
					logo.armY += screen.ycenter
					logo.arrayPos = 0
					object.state++
				end if
				logo.timer = 0
			end if

			DrawSpriteScreenXY(logo.p2Frame, logo.player2X, logo.player2Y)
			if logo.p2Frame == 16
				DrawSpriteScreenXY(17, logo.armX, logo.armY)
			end if
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if options.region == 1
				DrawSpriteScreenXY(33, logo.charTitlePos, 258)
			else
				DrawSpriteScreenXY(31, logo.charTitlePos, 258)
			end if
			DrawSpriteScreenXY(36, logo.charTitlePos, 258)
			break

		case LOGO_ARMAPPEARP2_SONIC
			screen.xoffset += 2

			temp0 = logo.arrayPos
			GetTableValue(logo.armX, temp0, Logo_TailsArmOffsets)
			logo.armX += screen.xcenter
			logo.armX -= 24
			temp0++

			GetTableValue(logo.armY, temp0, Logo_TailsArmOffsets)
			logo.armY += screen.ycenter
			logo.armY -= 24

			logo.timer++
			logo.timer &= 3
			if logo.timer == 0
				logo.arrayPos += 2
				if logo.arrayPos == 4
					object.state++
				end if
			end if

			DrawSpriteScreenXY(logo.p2Frame, logo.player2X, logo.player2Y)
			DrawSpriteScreenXY(17, logo.armX, logo.armY)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if options.region == 1
				DrawSpriteScreenXY(33, logo.charTitlePos, 228)
			else
				DrawSpriteScreenXY(31, logo.charTitlePos, 228)
			end if
			DrawSpriteScreenXY(36, logo.charTitlePos, 228)
			break

		case LOGO_ANIMATEP1_SONIC
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 8
				object.frame++
				if object.frame > 8
					object.frame = 7
				end if
				logo.timer = 0
			end if

			DrawSpriteScreenXY(logo.p2Frame, logo.player2X, logo.player2Y)
			DrawSpriteScreenXY(17, logo.armX, logo.armY)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if options.region == 1
				DrawSpriteScreenXY(33, logo.charTitlePos, 228)
			else
				DrawSpriteScreenXY(31, logo.charTitlePos, 228)
			end if
			DrawSpriteScreenXY(36, logo.charTitlePos, 228)
			break
		end switch
		break

	case 1
		switch object.state
		case LOGO_SETUP_TAILS
			screen.xoffset 		 = 0

			object.priority 	 = PRIORITY_ACTIVE
			logo.timer 			 = 1000
			stage.activeLayer[0] = 1
			object.state++

			SetScreenFade(0x00, 0x00, 0x00, 0xFF)
			break

		case LOGO_FADEIN_TAILS
			screen.xoffset += 2

			if logo.timer > 0
				logo.timer -= 8
			else
				PlayMusic(0)
				object.state++
			end if

			SetScreenFade(0x00, 0x00, 0x00, logo.timer)
			break

		case LOGO_RISEDELAY_TAILS
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 38
				logo.timer = 0
				object.frame = 12
				object.state++
			end if
			break

		case LOGO_RISE_TAILS
			screen.xoffset += 2

			temp0 = logo.arrayPos
			GetTableValue(logo.playerX, temp0, Logo_TailsBodyOffsets)
			logo.playerX += screen.xcenter
			temp0++

			GetTableValue(logo.playerY, temp0, Logo_TailsBodyOffsets)
			logo.playerY += screen.ycenter

			logo.timer++
			logo.timer &= 3
			if logo.timer == 0
				logo.arrayPos += 2
				if logo.arrayPos == 14
					object.state++
				end if
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			break

		case LOGO_ANIMATE_TAILS
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 2
				object.frame++
				if object.frame >= 16
					object.frame = 16
					object[+1].type 	= TypeName[Start Message]
					object[+1].priority = PRIORITY_ACTIVE
					object[+1].xpos 	= screen.xcenter
					object[+1].ypos 	= 216
					logo.armX = 8
					logo.armX += screen.xcenter
					logo.armY = -27
					logo.armY += screen.ycenter
					logo.arrayPos = 0
					object.state++
				end if
				logo.timer = 0
			end if

			if object.frame == 16
				DrawSpriteScreenXY(17, logo.armX, logo.armY)
			end if
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			break

		case LOGO_ARMAPPEAR_TAILS
			screen.xoffset += 2

			temp0 = logo.arrayPos
			GetTableValue(logo.armX, temp0, Logo_TailsArmOffsets)
			logo.armX += screen.xcenter
			temp0++

			GetTableValue(logo.armY, temp0, Logo_TailsArmOffsets)
			logo.armY += screen.ycenter

			logo.timer++
			logo.timer &= 3
			if logo.timer == 0
				logo.arrayPos += 2
				if logo.arrayPos == 4
					object.state++
				end if
			end if

			DrawSpriteScreenXY(17, logo.armX, logo.armY)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			break

		case LOGO_PREPLOGOAPPEAR_TAILS
			screen.xoffset += 2

			object.ypos++
			logo.playerY++
			logo.armY++
			if object.ypos >= 24
				object.state++
			end if

			DrawSpriteScreenXY(9, screen.xcenter, object.ypos)
			DrawSpriteScreenXY(17, logo.armX, logo.armY)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			break

		case LOGO_SHOWLOGO_TAILS
			screen.xoffset += 2

			if logo.charTitlePos >= 89
				if logo.speedPercent == 0
					logo.timer++
					if logo.timer == 3
						logo.charTitlePos = 89
						object.state++
					end if
					logo.speedPercent = 1
				end if
				object.yvel -= 0x4000
				if object.yvel > 0
					object.yvel -= 0x8000
				end if
			else
				logo.speedPercent = 0
				object.yvel += 0x6000
				if object.yvel < 0
					object.yvel += 0x8000
				end if
			end if
			logo.speedPercent += object.yvel
			temp0 = logo.speedPercent
			temp0 >>= 16
			logo.charTitlePos += temp0
			logo.speedPercent &= 0xFFFF

			DrawSpriteScreenXY(17, logo.armX, logo.armY)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if options.region == 1
				DrawSpriteScreenXY(33, screen.xcenter, logo.charTitlePos)
				DrawSpriteScreenXY(34, screen.xcenter, logo.charTitlePos)
			else
				DrawSpriteScreenXY(31, screen.xcenter, logo.charTitlePos)
				DrawSpriteScreenXY(32, screen.xcenter, logo.charTitlePos)
			end if
			DrawSpriteScreenXY(35, screen.xcenter, logo.charTitlePos)
			break

		case LOGO_IDLE_TAILS
			screen.xoffset += 2

			DrawSpriteScreenXY(17, logo.armX, logo.armY)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if options.region == 1
				DrawSpriteScreenXY(33, screen.xcenter, logo.charTitlePos)
				DrawSpriteScreenXY(34, screen.xcenter, logo.charTitlePos)
			else
				DrawSpriteScreenXY(31, screen.xcenter, logo.charTitlePos)
				DrawSpriteScreenXY(32, screen.xcenter, logo.charTitlePos)
			end if
			DrawSpriteScreenXY(35, screen.xcenter, logo.charTitlePos)
			break
		end switch
		break

	case 2
		switch object.state
		case LOGO_SETUP_KNUX
			screen.xoffset = 0

			object.priority = PRIORITY_ACTIVE
			logo.timer = 256
			stage.activeLayer[0] = 1
			object.state++

			SetScreenFade(0x00, 0x00, 0x00, 0xFF)
			break

		case LOGO_FADEIN_KNUX
			screen.xoffset += 2

			if logo.timer > 0
				logo.timer -= 8
			else
				PlayMusic(0)
				object.state++
			end if

			SetScreenFade(0x00, 0x00, 0x00, logo.timer)
			break

		case LOGO_RISEDELAY_KNUX
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 38
				logo.timer = 0
				logo.playerX = -44
				logo.playerX += screen.xcenter
				logo.playerY = -22
				logo.playerY += screen.ycenter
				object.frame = 18
				object.state++
			end if
			break

		case LOGO_RISE_KNUX
			screen.xoffset += 2

			logo.playerY -= 8
			temp0 = screen.ycenter
			temp0 -= 94
			if logo.playerY <= temp0
				object.state++
			end if
			temp0 += 32
			if logo.playerY == temp0
				object.frame++
				logo.armFrame = 24
				logo.armX = -44
				logo.armX += screen.xcenter
				logo.armY = -46
				logo.armY += screen.ycenter
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			break

		case LOGO_ANIMATE_KNUX
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 8
				object.frame++
				if object.frame >= 23
					object.frame = 23
					object[+1].type 	= TypeName[Start Message]
					object[+1].priority = PRIORITY_ACTIVE
					object[+1].xpos 	= screen.xcenter
					object[+1].ypos 	= 216
					object.state++
				end if
				logo.timer = 0
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			if object.frame >= 23
				DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			end if
			break

		case LOGO_ARMAPPEAR_KNUX
		case LOGO_ARMAPPEAR2_KNUX
			screen.xoffset += 2

			logo.armY--
			logo.timer++
			if logo.timer == 4
				logo.timer = 0
				object.state++
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			break

		case LOGO_ANIMATEARM_KNUX
		case LOGO_ANIMATEARM2_KNUX
			screen.xoffset += 2

			logo.timer++
			if logo.timer == 4
				logo.timer = 0
				logo.armFrame++
				if logo.armFrame == 29
					logo.armFrame = 24
					object.state++
				end if
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			break

		case LOGO_MOVEARM_KNUX
		case LOGO_MOVEARM2_KNUX
			screen.xoffset += 2

			logo.armY++
			logo.timer++
			if logo.timer == 4
				logo.timer = 0
				object.state++
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			break

		case LOGO_PREPLOGOAPPEAR_KNUX
			screen.xoffset += 2

			object.yvel += 0x4000
			logo.speedPercent += object.yvel
			temp0 = logo.speedPercent
			temp0 >>= 16
			object.ypos += temp0
			logo.playerY += temp0
			logo.armY += temp0
			logo.speedPercent &= 0xFFFF
			if object.yvel > 0
				if object.ypos >= 24
					object.yvel >>= 1
					temp0 = object.yvel
					temp0 >>= 1
					object.yvel += temp0
					logo.timer++
					if logo.timer != 3
						FlipSign(object.yvel)
					else
						logo.timer = 0
						object.yvel = 0
						object.state++
					end if
				end if
			end if

			DrawSpriteScreenXY(9, screen.xcenter, object.ypos) // Logo (Top Half)
			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			break

		case LOGO_SHOWLOGO_KNUX
			screen.xoffset += 2

			object.yvel += 0x4000
			logo.speedPercent += object.yvel
			temp0 = logo.speedPercent
			temp0 >>= 16
			logo.charTitlePos += temp0
			logo.speedPercent &= 0xFFFF
			if object.yvel > 0
				if logo.charTitlePos >= 89
					object.yvel >>= 2
					temp0 = object.yvel
					temp0 >>= 1
					object.yvel += temp0
					logo.timer++
					if logo.timer != 2
						FlipSign(object.yvel)
					else
						logo.timer = 0
						object.yvel = 0
						object.state++
					end if
				end if
			end if

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			DrawSpriteScreenXY(30, screen.xcenter, logo.charTitlePos) // "Knux In" sprite
			break

		case LOGO_IDLE_KNUX
			screen.xoffset += 2

			DrawSpriteScreenXY(object.frame, logo.playerX, logo.playerY)
			DrawSpriteScreenXY(logo.armFrame, logo.armX, logo.armY)
			DrawSpriteScreenXY(30, screen.xcenter, logo.charTitlePos) // "Knux In" sprite
			break
		end switch
		break
	end switch

	//Logo (Bottom Half)
	DrawSpriteScreenXY(10, screen.xcenter, object.ypos)

	//Copyright Sprite
	temp0 = screen.xsize
	temp0 -= 96
	DrawSpriteScreenXY(11, temp0, 216)
end event


event ObjectStartup
	LoadSpriteSheet("Title/Title.gif")
	SetMusicTrack("Titlescreen.ogg", 0, false)

	SpriteFrame(-59, -96, 132, 130, 522, 250) 		// #0  - Sonic Frame 1
	SpriteFrame(-59, -96, 132, 130, 522, 250)              // #1  - Sonic Frame 2
	SpriteFrame(-59, -96, 132, 130, 656, 250) 		// #2  - Sonic Frame 3
	SpriteFrame(-59, -96, 132, 130, 522, 250) 	        // #3  - Sonic Frame 4
	SpriteFrame(-59, -96, 132, 130, 656, 250) 		// #4  - Sonic Frame 5
	SpriteFrame(-59, -96, 132, 130, 522, 250)  		// #5  - Sonic Frame 6
	SpriteFrame(-59, -96, 132, 130, 656, 250) 		// #6  - Sonic Frame 7
	SpriteFrame(-59, -96, 132, 130, 522, 250) 		// #7  - Sonic Frame 8
	SpriteFrame(-59, -96, 132, 130, 522, 250)  		// #8  - Sonic Frame 9
	SpriteFrame(-128, 22, 271, 118, 531, 44) 	// #9  - Logo (Top)
	SpriteFrame(-128, 140, 271, 74, 531, 162) 	// #10 - Logo (Bottom)
	SpriteFrame(0, 0, 71, 17, 182, 210) 		// #11 - Copyright Sprite
	SpriteFrame(-21, -16, 162, 135, 803, 1) 		// #12 - Tails Frame 1
	SpriteFrame(-21, -16, 162, 135, 803, 1) 		// #13 - Tails Frame 2
	SpriteFrame(-21, -16, 162, 135, 803, 1) 		// #14 - Tails Frame 3
	SpriteFrame(-21, -16, 162, 135, 803, 1) 		// #15 - Tails Frame 4
	SpriteFrame(-21, -16, 162, 135, 803, 1) 		// #16 - Tails Frame 5
	SpriteFrame(8, 5, 16, 19, 452, 5) 			// #17 - Tails' Arm
	SpriteFrame(3, 15, 101, 47, 2, 439) 		// #18 - Knux Frame 1
	SpriteFrame(3, 15, 101, 73, 2, 439) 		// #19 - Knux Frame 2
	SpriteFrame(0, 9, 95, 79, 104, 433) 		// #20 - Knux Frame 3
	SpriteFrame(1, 6, 105, 82, 200, 430) 		// #21 - Knux Frame 4
	SpriteFrame(1, 4, 102, 84, 306, 428) 		// #22 - Knux Frame 5
	SpriteFrame(5, 2, 91, 86, 409, 426) 		// #23 - Knux Frame 6
	SpriteFrame(8, 5, 42, 43, 469, 5) 			// #24 - Knux' Arm Frame 1
	SpriteFrame(8, 3, 40, 53, 218, 310) 		// #25 - Knux' Arm Frame 2
	SpriteFrame(8, 8, 40, 39, 471, 49) 			// #26 - Knux' Arm Frame 3
	SpriteFrame(8, 8, 40, 39, 471, 49) 			// #27 - Knux' Arm Frame 4
	SpriteFrame(8, 3, 40, 53, 218, 310) 		// #28 - Knux' Arm Frame 5
	SpriteFrame(8, 5, 42, 43, 469, 5) 			// #29 - Knux' Arm Frame 6
	SpriteFrame(-124, -66, 248, 65, 1, 364) 	// #30 - Knux In
	SpriteFrame(-77, -66, 153, 42, 1, 222) 		// #31 - "Tails"
	SpriteFrame(-77, -23, 93, 10, 155, 231) 	// #32 - "Miles Prower"
	SpriteFrame(-77, -66, 153, 42, 1, 179) 		// #33 - "Miles"
	SpriteFrame(-77, -23, 103, 10, 155, 242) 	// #34 - "Tails Prower"
	SpriteFrame(52, -19, 24, 18, 165, 411) 		// #35 - "In"
	SpriteFrame(-101, -66, 28, 42, 189, 321) 	// #36 - "&"

	temp0 = 208
	temp1 = 0
	while temp1 < 14
		GetTableValue(temp2, temp1, Logo_PlayerColors)
		SetPaletteEntry(0, temp0, temp2)
		temp0++
		temp1++
	loop
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event